package de.tum.activities.StatsApp;



import org.achartengine.ChartFactory;
import org.achartengine.GraphicalView;
import org.achartengine.model.CategorySeries;
import org.achartengine.renderer.DefaultRenderer;
import org.achartengine.renderer.SimpleSeriesRenderer;

import android.R.color;
import android.content.Context;
import android.graphics.Color;

public class GradingDistributionPieChart {
		 
	public GraphicalView execute(Context context, int[] grade_distribution) {
		int[] colors = new int[grade_distribution.length];
		for(int i=0; i<colors.length; i++){
			if(i<4)
				colors[i] = Color.GREEN;
			else if(i<10)
				colors[i] = Color.YELLOW;
			else
				colors[i] = Color.RED;
		}
		DefaultRenderer renderer = buildCategoryRenderer(colors);
		 
		CategorySeries categorySeries = new CategorySeries("Vehicles Chart");
		categorySeries.add("1.0", grade_distribution[0]);
		categorySeries.add("1.3", grade_distribution[1]);
		categorySeries.add("1.7", grade_distribution[2]);
		categorySeries.add("2.0", grade_distribution[3]);
		categorySeries.add("2.3", grade_distribution[4]);
		categorySeries.add("2.7", grade_distribution[5]);
		categorySeries.add("3.0", grade_distribution[6]);
		categorySeries.add("3.3", grade_distribution[7]);
		categorySeries.add("3.7", grade_distribution[8]);
		categorySeries.add("4.0", grade_distribution[9]);
		categorySeries.add("4.3", grade_distribution[10]);
		categorySeries.add("4.7", grade_distribution[11]);
		categorySeries.add("5.0", grade_distribution[12]);
		
		return ChartFactory.getPieChartView(context, categorySeries, renderer);
	}
		 
	protected DefaultRenderer buildCategoryRenderer(int[] colors) {
		DefaultRenderer renderer = new DefaultRenderer();
		for (int i= 0; i<colors.length; i++) {
			int color = colors[i];
			SimpleSeriesRenderer r = new SimpleSeriesRenderer();
			r.setColor(color);
			renderer.addSeriesRenderer(r);
		}
		return renderer;
	}
}